LIBRARY IEEE; 
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

--BCD TO SEVEN SEGMENT

ENTITY ic_6 IS

    PORT(clear, pin1, pin2, pin3, pin4, pin5, pin6, pin7: IN STD_LOGIC := '0'; 
        pin9, pin10, pin11, pin12, pin13, pin14, pin15: OUT STD_LOGIC  := '0');

END ic_6;

ARCHITECTURE bcdto7seg_ic OF ic_6 IS

SIGNAL SEG: STD_LOGIC_VECTOR(6 DOWNTO 0) := "0000000";
SIGNAL BCD: STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";

BEGIN

    pin13 <= SEG(0);
    pin12 <= SEG(1);
    pin11 <= SEG(2);
    pin10 <= SEG(3);
    pin9 <= SEG(4);
    pin15 <= SEG(5);
    pin14 <= SEG(6);
	 
    BCD(0) <= pin7;
    BCD(1) <= pin1;
    BCD(2) <= pin2;
    BCD(3) <= pin6;
	 
    PROCESS(BCD, pin3, pin4, pin5, clear)
    BEGIN
        IF(pin4 = '0' OR clear = '1') THEN
            SEG <= "0000000";
        ELSIF(pin3 = '0') THEN
            SEG <= "1111111";
        ELSIF(pin5 = '0' AND BCD = "0000") THEN
            SEG <= "0000000";
        ELSE
            CASE BCD IS
                WHEN "0000" =>
                    SEG <= "0111111";
                WHEN "0001" =>
                    SEG <= "0000110";
                WHEN "0010" =>
                    SEG <= "1011011";
                WHEN "0011" =>
                    SEG <= "1001111";
                WHEN "0100" =>
                    SEG <= "1100110";
                WHEN "0101" =>
                    SEG <= "1101101";
                WHEN "0110" =>
                    SEG <= "1111100";
                WHEN "0111" =>
                    SEG <= "0000111";
                WHEN "1000" =>
                    SEG <= "1111111";
                WHEN "1001" =>
                    SEG <= "1100111";
                WHEN "1010" =>
                    SEG <= "1011000";
                WHEN "1011" =>
                    SEG <= "1001100";
                WHEN "1100" =>
                    SEG <= "1100010";
                WHEN "1101" =>
                    SEG <= "1101001";
                WHEN "1110" =>
                    SEG <= "1111000";
                WHEN OTHERS =>
                    SEG <= "0000000";
            END CASE;
        END IF;
    END PROCESS;

END bcdto7seg_ic;